package com.mimiwang.user.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.mimiwang.common.utils.PageUtils;
import com.mimiwang.common.utils.R;
import com.mimiwang.user.entity.UserAttentionEntity;
import com.mimiwang.user.service.UserAttentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;


/**
 * 用户关注关系表
 *
 * @author hustart
 * @email hustart1@126.com
 * @date 2022-10-06 22:55:42
 */
@RestController
@RequestMapping("user/userattention")
public class UserAttentionController {
    @Autowired
    private UserAttentionService userAttentionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = userAttentionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        UserAttentionEntity userAttention = userAttentionService.getById(id);

        return R.ok().put("userAttention", userAttention);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserAttentionEntity userAttention) {
        userAttentionService.save(userAttention);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserAttentionEntity userAttention) {
        userAttentionService.updateById(userAttention);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        userAttentionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * @description 获取用户的关注列表
     * @param userId
     * @return
     */
    @GetMapping("/getAttentionList/{userId}")
    public R getAttentionList(@PathParam("userId") Long userId) {
        List<UserAttentionEntity> attentionList = userAttentionService.attentionList(userId);
        return R.ok().put("attentionList",attentionList);
    }


}
